﻿#ifndef PST_QTEXTREADER_H
#define PST_QTEXTREADER_H

#include <QFile>  
#include <QTextStream>  
#include <QVector>  
#include <QStringList>  
#include <QString>  
#include <iostream>  

namespace pst
{
    class QTextReader :public QObject
    {
        Q_OBJECT
    public:
        QTextReader(QObject* parent = nullptr);

        //设置文件路径
        inline void setFilePath(const QString& filePath) { m_filePath = filePath; }
        QString getFilePath() const { return m_filePath; };

        void setHasHeader(bool hasHeader);
        //设置分隔符
        void setSplitter(const QString& splitter) { m_splitter = splitter; }
        QString getSplitter() const { return m_splitter; };

        void setHirf2DFormart(bool isHirf2D);
        bool doRead(QString& error = QString());

        // 获取列名
        inline QStringList getColuneNames() const { return m_headers; }

        // 通过下标获取列数据
        QVector<double> getColuneData(int index) const { return m_allData[index].second; }

        // 获取所有数据 列名，列数据  按读取的顺序返回
        QVector<QPair<QString, QVector<double>>> getAllData() const { return m_allData; }

    private:
        QStringList m_headers{};
        QString m_filePath{};
        QString m_splitter{ "," };
        QVector<QPair<QString, QVector<double>>>  m_allData;
        bool m_isHirf2D;
        bool m_hasHeader;
    };
}

#endif
